package com.karry.yl.service.elder.impl;

import com.karry.commons.base.impl.SuperServiceImpl;
import com.karry.yl.dao.elder.TranseferMapper;
import com.karry.yl.domain.baseinfo.Organization;
import com.karry.yl.domain.elder.Elderly;
import com.karry.yl.domain.elder.Transefer;
import com.karry.yl.service.baseinfo.OrganizationService;
import com.karry.yl.service.elder.ElderlyService;
import com.karry.yl.service.elder.TranseferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class TranseferServiceImpl extends SuperServiceImpl<TranseferMapper, Transefer> implements TranseferService {

    @Autowired
    private ElderlyService elderlyService;
    @Autowired
    private OrganizationService organizationService;

    @Override
    public void agree(Long id) {
        Transefer transefer = baseMapper.selectById(id);
        Elderly elderly = elderlyService.selectById(transefer.getElderlyId());
        elderly.setOrgId(transefer.getToId());
        elderly.setMealId(-1L);
        elderly.setMealName("");
        Organization organization = organizationService.selectById(transefer.getToId());
        //关联民政部门信息
        elderly.setMzName(organization.getMzName());
        elderly.setMzCode(organization.getMzCode());
        elderlyService.updateById(elderly);
        transefer.setStatus(Transefer.STATUS_YZ);  //同意
        baseMapper.updateById(transefer);
    }
}
